package ru.gerunn.study.threads;

class ToInterrupt extends Thread {
	@Override
	public void run() {
		while (true) {
			System.out.println("LA-LA-LA!");
			synchronized (this) {
				try {
					wait();
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
		}
	}
}

class Interrupter implements Runnable {

	ToInterrupt toInterrupt;

	public Interrupter(ToInterrupt toInterrupt) {
		this.toInterrupt = toInterrupt;
	}

	public void run() {
		while (true) {
			synchronized (toInterrupt) {
				toInterrupt.notify();
			}
			try {
				Thread.sleep(3000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
}

public class Interruption {

	public static void main(String[] args) {
		ToInterrupt toInterrupt = new ToInterrupt();
		Thread interrupter = new Thread(new Interrupter(toInterrupt));

		toInterrupt.start();
		interrupter.start();
	}

}
